<template>
	<view class="content">
		<navTop :title="navtop.title" :isHeight="false" :tipsShow="false" hasBgc="#fff" :color="navtop.color" :isBack="true" ></navTop>
		<view class="content-box" :style="{paddingTop:barHeight+'rpx'}">
			<view class="content-item">
				<view class="content-list__title">
					<view class="content-list__title">
						<image :src="row.accountHead" mode="" class="content-list__title-img" @click="gotoDetail"></image>
						<view>
							<view>{{row.accountName}}</view>
							<text class="content-list__title-time">{{row.tips}}</text>
						</view>
					</view>
					<view class="content-list__textB" :class="{unfollow: row.followState}" @click="followUser(row.followState)">
						{{row.followState ? 'unFollow' : 'Follow'}}
					</view>
				</view>
				<view class="content-list__text">
					{{row.content || ''}}
				</view>
				<view class="content-list__imgs">
					<image :src="item.imgUrl" mode="aspectFit" class="content-list__imgs-item" v-for="(item, i) in row.imgList" :key="i" @click="searchImg(i, row.imgList)">
					
					</image>
				</view>
				<view class="content-list__btns" @click.stop="addLike(row)">
					<image :src="row.isLike ? like : notLike" mode="" class="content-list__btns-img"></image>
					<text>{{row.likes || 0}}</text>
				</view>
				<view class="content-list__user">
					<view>
						<image v-for="(v, i) in row.likerList" :key="i" :src="v" mode="aspectFill" class="content-user__item"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
import banner from '@/static/home_active.png'
import navTop from '@/components/nav-title.vue';
import like from '@/static/like.png'
import notLike from '@/static/not-like.png'

	export default {
		components: {
			navTop
		},
		data() {
			return {
				banner,
				like,
				notLike,
				barHeight: 0,
				navtop: {
					title: 'detail',
					color: '#000'
				},
				row: {},
				squareList: [
					{
						name: 'Popular',
						like: true
					},
					{
						name: 'Follow'
					},
					{
						name: 'Follow'
					}
				],
				userList: [
				]
			}
		},
		onLoad(e) {
			this.$http('get', '/app/dynamic/getById', {
				id: e.id || ''
			}).then((res) => {
				if (res.success) {
					res.data.tips = this.$utils.getTimerOff(res.data.createTime)
					this.row = res.data
					console.log(this.row, this.row.likerList)
				}
			})
		},
		created() {
			this.isBarHeight999().then((statusBarHeight)=>{
				this.barHeight = statusBarHeight + 180
				console.log(this.barHeight)
			})
		},
		methods: {
			searchImg(i, imgList) {
				imgList = imgList.map((v) => {
					return v.imgUrl
				})
				uni.previewImage({
					current:i, //预览图片的下标
					urls: imgList//预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
			gotoDetail() {
				uni.navigateTo({
					url: '/pages/me/userDetail?id=' + this.row.accountId
				})
			},
			followUser(followState) {
				this.$http('post', '/app/follow', {
					dynamicId: this.row.id,
					accountId: this.row.accountId
				}, {
					'Content-Type': 'application/x-www-form-urlencoded'
				}).then((res) => {
					if (res.success) {
						if (followState == 1) {
							this.row.followState = 0
						} else {
							this.row.followState = 1
						}
					}
				})
			},
			addLike(v) {
				this.$http('get', '/app/thumbs', {
					dynamicId: v.id
				}).then((res) => {
					if (res.success) {
						if (v.isLike == 1) {
							v.isLike = 0
							v.likes -= 1
						} else {
							v.isLike = 1
							v.likes += 1
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
.content {
	background-color: #fff;
	// padding: 0 30px;
	min-height: 100vh;
}
.content-box {
	font-size: 40rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #1F1F1F;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 34rpx;
	.content-box__btn {
		display: inline-block;
		padding: 16rpx 32rpx;
		font-size: 28rpx;
		color: #fff;
		background: #0078FF;
		border-radius: 18px;
	}
}
.content-item {
		background-color: #fff;
		padding: 32rpx 40rpx;
		box-sizing: border-box;
		width: 100%;
		margin-bottom: 16rpx;
		.content-list__title {
			height: 80rpx;
			display: flex;
			justify-content: space-between;
			align-items: flex-start;
			font-size: 32rpx;
			font-family: Helvetica;
			color: #1F1F1F;
			margin-bottom: 8rpx;
		}
		.content-list__textB {
			padding: 14rpx 36rpx;
			font-size: 24rpx;
			font-family: Helvetica;
			color: #FFFFFF;
			background: #0078FF;
			border-radius: 36rpx;
		}
		.content-list__text {
			margin: 32rpx 0;
			font-size: 30rpx;
			font-family: Helvetica;
			color: #1F1F1F;
		}
		.content-list__title-time {
			font-size: 22rpx;
			font-family: Helvetica;
			color: rgba(31, 31, 31, 0.45);
		}
		.content-list__title-img {
			width: 80rpx;
			height: 80rpx;
			margin-right: 20rpx;
			border-radius: 50%;
		}
	}
	
.content-list__btns {
	display: flex;
	justify-content: flex-start;
	align-items: center;
	font-size: 28rpx;
	font-family: Helvetica;
	color: rgba(31, 31, 31, 0.45);
	.content-list__btns-img {
		width: 48rpx;
		height: 48rpx;
		margin-right: 8rpx;
	}
}

.content-list__imgs {
	display: flex;
	justify-content: flex-start;
	align-items: flex-start;
	margin-bottom: 32rpx;
	.content-list__imgs-item {
		width: 190rpx;
		height: 190rpx;
		border-radius: 8rpx;
		background-color: #000;
		margin-right: 18rpx;
	}
}

.content-list__user {
	display: flex;
	justify-content: flex-start;
	align-items: flex-start;
	flex-wrap: wrap;
	margin-top: 32rpx;
	.content-user__item {
		width: 60rpx;
		height: 60rpx;
		margin: 0 10rpx 16rpx 0;
		border-radius: 50%;
	}
}
.unfollow {
	background: #FFFFFF !important;
	border-radius: 36rpx !important;
	border: 1px solid #0078FF !important;
	font-size: 24rpx !important;
	font-family: Helvetica !important;
	color: #0078FF !important;
	padding: 14rpx 24rpx !important;
}
</style>
